<?php 
namespace FrontEnd\Navigation;

use Zend\ServiceManager\ServiceLocatorInterface;
use Zend\Navigation\Service\DefaultNavigationFactory;

class Navigation extends DefaultNavigationFactory
{
	protected function getPages(ServiceLocatorInterface $serviceLocator)
	{
		if (null === $this->pages) {
		 //lấy dữ liệu từ bảng menu menu :
         //var_dump('ok');
         $fetchMenu = $serviceLocator->get('menu_frontend')->fetchAll();
        // $fetchMenu = array('das','gfer');
         $configuration['navigation'][$this->getName()] = array();
         // gán dữ liệu vào configuration['navigation']
         foreach($fetchMenu as $key=>$row){
         	//$fetchsubMenu = $serviceLocator->get('albumss')->fetchAllSubMenus($row['id']);
            $configuration['navigation'][$this->getName()][$row['ID_M']] = array(
                  'label' => $row['LABEL_M'],
                  'route' => $row['ROUTE_M'],
            	  
            );
         }

	$application = $serviceLocator->get('Application');
	$routeMatch = $application->getMvcEvent()->getRouteMatch();
	$router = $application->getMvcEvent()->getRouter();
	$pages = $this->getPagesFromConfig($configuration['navigation'][$this->getName()]);

$this->pages = $this->injectComponents($pages, $routeMatch, $router);
}
return $this->pages;
}
} 
/* namespace Application\Navigation;

use Zend\ServiceManager\ServiceLocatorInterface;
use Zend\Navigation\Service\DefaultNavigationFactory;
//use Application\Model\MenuTable;
 class Navigation extends DefaultNavigationFactory
{
protected function getPages(ServiceLocatorInterface $serviceLocator){
      if (null === $this->pages) {
         //lấy dữ liệu từ bảng menu menu :
         //var_dump('ok');
         $fetchMenu = $serviceLocator->get('albumss')->fetchAll();
        // $fetchMenu = array('das','gfer');
         $configuration['navigation'][$this->getName()] = array();
         // gán dữ liệu vào configuration['navigation']
         foreach($fetchMenu as $key=>$row){
         	//$fetchsubMenu = $serviceLocator->get('albumss')->fetchAllSubMenus($row['id']);
            $configuration['navigation'][$this->getName()][$row['title']] = array(
                  'label' => $row['label'],
                  'route' => $row['route'],
            	  
            );
         }

         $application = $serviceLocator->get('Application');// Lấy các thông tin đăng ký service
         $routeMatch  = $application->getMvcEvent()->getRouteMatch(); // Lấy ra các thông số route
         $router      = $application->getMvcEvent()->getRouter(); // lấy ra các giá trị trên url
         $pages       = $this->getPagesFromConfig($configuration['navigation'][$this->getName()]); // lấy ra mảng config của Zend\Config\Config

         $this->pages = $this->injectComponents($pages, $routeMatch, $router);
      }
      return $this->pages;
   }
} */
